# -*- coding: utf-8 -*-

import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *


class MainWindow(QWidget):

    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent=parent)

        self.setWindowTitle("ComBox示例")
        self.resize(300, 90)
        layout = QVBoxLayout()
        self.lb1 = QLabel("")

        self.cb = QComboBox()
        self.cb.addItem("C")
        self.cb.addItem("C++")
        self.cb.addItems(["Java", "C#", "Python"])
        self.cb.currentIndexChanged.connect(self.selectionChange)

        layout.addWidget(self.cb)
        layout.addWidget(self.lb1)
        self.setLayout(layout)

    def selectionChange(self, i):
        self.lb1.setText(self.cb.currentText())
        print("Items in the list are:")
        for count in range(self.cb.count()):
            print("Item%d = %s" % (count, self.cb.itemText(count)))
            print("Current index %d selection changed %s" % (i, self.cb.currentText()))


if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = MainWindow()
    win.show()
    sys.exit(app.exec())